<template>
  <div class="ipt">
    <textarea v-model="val"></textarea>
    <button @click="send">发送评论</button>
  </div>
</template>
<script>
import * as commentApi from "@/api";
import { mapActions } from "vuex";
export default {
  data() {
    return {
      val: "",
    };
  },
  methods: {
    ...mapActions(["GET_COMMENT_LIST"]),
    send() {
      if (this.val !== "") {
        let name = prompt("请输入您的昵称！");
        if (name !== "") {
          commentApi.addComment(this.val, name).then((res) => {
            console.log(res);
            if (res.data.state) {
              console.log(1);
              this.GET_COMMENT_LIST();
              this.val = "";
            }
          });
        }
      }
    },
  },
};
</script>
<style scoped>
.ipt {
  width: 100%;
  height: 200px;
  overflow-y: scroll;
}
.ipt textarea {
  width: 100%;
  height: 150px;
}
.ipt button {
  background-color: #ee509f;
}
</style>
